import 'package:flutter/material.dart';
import 'package:flutter_bilibili/navigator/fw_navigator.dart';
import 'package:flutter_bilibili/widget/appbar.dart';
import 'package:flutter_bilibili/widget/login_button.dart';
import 'package:flutter_bilibili/widget/login_effect.dart';
import 'package:flutter_bilibili/widget/login_input.dart';
import 'package:get/get.dart';

import 'login_logic.dart';

class GetxLoginPage extends StatelessWidget {
  const GetxLoginPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final logic = Get.find<LoginLogic>();
    final state = Get.find<LoginLogic>().state;

    return Scaffold(
      appBar: appBar('Getx密码登录', '注册', () {
        FwNavigator.getInstance().onJumpTo(RouteStatus.registration);
      }),
      body: Obx(() {
        return ListView(
          children: [
            LoginEffect(protect: logic.protect.value),
            LoginInput(
              '用户名',
              '请输入用户',
              onChanged: (text) {
                logic.userName = text;
                logic.checkInput();
              },
            ),
            LoginInput(
              '密码',
              '请输入密码',
              obscureText: true,
              onChanged: (text) {
                logic.password = text;
                logic.checkInput();
              },
              focusChanged: (focus) {
                logic.protect.value = focus;
              },
            ),
            Padding(
                padding: const EdgeInsets.only(left: 20, right: 20, top: 20),
                child: LoginButton(
                  '登录',
                  enable: logic.loginEnable.value,
                  onPressed: logic.send,
                )),
          ],
        );
      })
    );
  }
}
